#include <bits/stdc++.h>
using namespace std;

int a[10005], c[100005];

int maxn = 0, n;

void dfs(int dep)
{
    if (dep > n)
    {
        int sum = 0;
        for (int i = 2; i <= n; i++)
            for (int j = i - 1; i >= 1; i--)
                if (a[i] == a[j] && c[i] == c[j])
                {
                    sum += a[i];
                    break;
                }
        maxn = max(maxn, sum);
    }
    else
    {
        c[dep] = 1;
        dfs(dep + 1);
        c[dep] = 0;
        dfs(dep + 1);
    }
}

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.in", "w", stdout);
    int t;
    cin >> t;
    while (t--)
    {
        maxn = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        dfs(1);
        cout << maxn << "\n";
    }
    return 0;
}